<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/28
 * Time: 14:44
 */

class GoodsController extends BaseController
{
    /*
    |--------------------------------------------------------------------------
    | 产品控制器
    |--------------------------------------------------------------------------
    |   GetProductList            产品信息
    |   GetProductDetail          产品详情
    |
    */


    /**
     * 产品分类列表
     * @return mixed
     * @author alice
     * @date 2016-1-13
     */
    public function ShowGoodsCate()
    {
        $info = GoodsService::instance()->GetGoodsCateList();
        return $this->view('admin.show_product_cate')->with('cates',$info);
    }

    /**
     * 新增产品分类
     * @return mixed
     * @author alice
     * @date 2016-1-13
     */
    public function AddGoodsCate()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData                     =     new stdClass();
            $aData->cate_name          =     $this->getParam('cate_name');
            $aData->parent_id          =     $this->getParam('parent_id');
            $aData->length             =     $this->getParam('length');
            $aData->description        =     $this->getParam('description');

            #逻辑操作
            GoodsService::instance()->AddGoodsCate($aData);
            return Redirect::to('/show_goods_cate');}else{
            $info = GoodsService::instance()->GetGoodsCateList();
            return $this->view('admin.add_product_cate')->with(['cates'=>$info, 'levels'=>ProductEnum::$product_level]);
        }
    }

    /**
     * 修改产品分类
     * @return mixed
     * @author alice
     * @date 2016-1-13
     */
    public function EditGoodsCate()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->cate_id            =     $this->getParam('cate_id');
            $aData->cate_name          =     $this->getParam('cate_name');
            $aData->parent_id          =     $this->getParam('parent_id');
            $aData->length             =     $this->getParam('length');
            $aData->description        =     $this->getParam('description');

            #逻辑操作
            GoodsService::instance()->EditGoodsCate($aData);
            return Redirect::to('/show_goods_cate');}else{
            $cate_id  =  $this->getParam('cate_id');
            $info = GoodsService::instance()->GetGoodsCateInfo($cate_id);
            $cate_list = GoodsService::instance()->GetGoodsCateList();
            return $this->view('admin.edit_product_cate')->with(['cate'=>$info,'cates'=>$cate_list, 'levels'=>ProductEnum::$product_level]);
        }
    }

    /**
     * 产品品牌列表
     * @return mixed
     * @author alice
     * @date 2016-1-13
     */
    public function ShowGoodsBrandList()
    {
        $info = GoodsService::instance()->ShowGoodsBrandList();
        return $this->view('admin.show_product_brand')->with('brands',$info);
    }

    /**
     * 新增产品品牌
     * @return mixed
     * @author alice
     * @date 2016-1-13
     */
    public function AddGoodsBrand()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->brand_name         =     $this->getParam('brand_name');
            $aData->start_time         =     $this->getParam('start_time');
            $aData->brand_img          =     $this->getParam('brand_img');

            #逻辑操作
            GoodsService::instance()->AddGoodsBrand($aData);
            return Redirect::to('/show_goods_brand');}else{
            return $this->view('admin.add_product_brand');
        }
    }

    /**
     * 修改产品品牌
     * @author alice
     * @date 2016-1-13
     * @return mixed
     */
    public function EditGoodsBrand()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->brand_id           =     $this->getParam('brand_id');
            $aData->brand_name         =     $this->getParam('brand_name');
            $aData->start_time         =     $this->getParam('start_time');
            $aData->brand_img          =     $this->getParam('brand_img');

            #逻辑操作
            GoodsService::instance()->EditGoodsBrand($aData);
            return Redirect::to('/show_goods_brand');}else{
            $id = $this->getParam('brand_id');
            $info = GoodsService::instance()->ShowGoodsBrandInfo($id);
            return $this->view('admin.edit_product_brand')->with('brand',$info);
        }
    }

    /**
     * 产品列表
     * @return mixed
     * @author alice
     * @date 2016-1-13
     */
    public function ShowGoodsList()
    {
        $info = GoodsService::instance()->ShowGoodsList();
        return $this->view('admin.show_product')->with('goods',$info);
    }

    /**
     * 新增产品
     * @return mixed
     * @author alice
     * @date 2016-1-13
     */
    public function AddGoods()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->product_name            =     $this->getParam('product_name');
            $aData->product_sn              =     $this->getParam('product_sn');
            $aData->brand_id                =     $this->getParam('brand_id');
            $aData->quality                 =     $this->getParam('quality');
            $aData->channel                 =     $this->getParam('channel');
            $aData->stock                   =     $this->getParam('stock');
            $aData->shop_price              =     $this->getParam('shop_price');
            $aData->description             =     $this->getParam('description');
            $aData->supplier                =     $this->getParam('supplier');
            $aData->place                   =     $this->getParam('place');
            $aData->spec                    =     $this->getParam('spec');
            $aData->level                   =     $this->getParam('level');
            $aData->storage                 =     $this->getParam('storage');
            $aData->start_num               =     $this->getParam('start_num');
            $aData->is_self_support         =     $this->getParam('is_self_support');
            $aData->is_index                =     $this->getParam('is_index');
            $aData->is_up                   =     $this->getParam('is_up');
            $aData->goods_img               =     $this->getParam('goods_img');

            #逻辑操作
            GoodsService::instance()->AddGoods($aData);
            return Redirect::to('/show_goods');
        }else{
            $goods_brand = GoodsService::instance()->ShowGoodsBrandList();
            $goods_cate = GoodsService::instance()->GetProductCateList();
            return $this->view('admin.add_product')->with(
                [
                    'brands'=>$goods_brand,
                    'cate'=>$goods_cate,
                    'channel'=>ProductEnum::$product_channel
                ]);
        }
    }

    /**
     * 修改产品
     * @author alice
     * @date 2016-1-13
     * @return mixed
     */
    public function EditGoods()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->product_id              =     $this->getParam('product_id');
            $aData->product_name            =     $this->getParam('product_name');
            $aData->product_sn              =     $this->getParam('product_sn');
            $aData->brand_id                =     $this->getParam('brand_id');
            $aData->cate_id                 =     $this->getParam('cate_id');
            $aData->channel                 =     $this->getParam('channel');
            $aData->stock                   =     $this->getParam('stock');
            $aData->shop_price              =     $this->getParam('shop_price');
            $aData->description             =     $this->getParam('description');
            $aData->supplier                =     $this->getParam('supplier');
            $aData->place                   =     $this->getParam('place');
            $aData->spec                    =     $this->getParam('spec');
            $aData->level                   =     $this->getParam('level');
            $aData->storage                 =     $this->getParam('storage');
            $aData->start_num               =     $this->getParam('start_num');
            $aData->is_self_support         =     $this->getParam('is_self_support');
            $aData->is_index                =     $this->getParam('is_index');
            $aData->is_up                   =     $this->getParam('is_up');
            $aData->goods_img               =     $this->getParam('goods_img');

            #逻辑操作
            GoodsService::instance()->EditGoods($aData);
            return Redirect::to('/show_goods');}else{
            $goods_brand = GoodsService::instance()->ShowGoodsBrandList();
            $goods_cate = GoodsService::instance()->GetGoodsCateList();
            $id   = $this->getParam('product_id');
            $info = GoodsService::instance()->GetGoodsInfo($id);
            return $this->view('admin.edit_product')->with(['product'=>$info, 'brands'=>$goods_brand,
                                                            'cate'=>$goods_cate, 'channel'=>ProductEnum::$product_channel]);
        }
    }

    /**
     * 产地展示列表
     * @return mixed
     * @author alice
     * @date 2016-2-19
     */
    public function ShowAreaList()
    {
        $info = GoodsService::instance()->ShowAreaList();
        return $this->view('admin.show_area')->with('areas',$info);
    }

    /**
     * 添加产地
     * @return mixed
     * @author alice
     * @date 2016-2-19
     */
    public function AddArea()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->area_name            =     $this->getParam('area_name');
            $aData->country              =     $this->getParam('country');

            #逻辑操作
            GoodsService::instance()->AddArea($aData);
            return Redirect::to('/show_area');
        }else{
            return $this->view('admin.add_area')->with('country',ProductEnum::$area);
        }
    }

    /**
     * 修改产地
     * @return mixed
     * @author alice
     * @date 2016-2-19
     */
    public function EditArea()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->area_id            =     $this->getParam('area_id');
            $aData->area_name          =     $this->getParam('area_name');
            $aData->country            =     $this->getParam('country');

            #逻辑操作
            GoodsService::instance()->EditArea($aData);
            return Redirect::to('/show_area');}else{
            $id   = $this->getParam('area_id');
            $info = GoodsService::instance()->GetAreaInfo($id);
            return $this->view('admin.edit_area')->with(['area'=> $info,'country'=>ProductEnum::$area]);
        }
    }

    /**
     * 标签列表
     * @return mixed
     * @author alice
     * @date 2016-1-25
     */
    public function ShowLabelList()
    {
        $info = GoodsService::instance()->ShowLabelList();
        return $this->view('admin.show_label')->with('labels',$info);
    }

    /**
     * 添加标签
     * @return mixed
     * @author alice
     * @date 2016-2-19
     */
    public function AddLabel()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->label_name            =     $this->getParam('label_name');
            $aData->quality               =     $this->getParam('quality');

            #逻辑操作
            GoodsService::instance()->AddLabel($aData);
            return Redirect::to('/show_label');}else{
            $quality = GoodsService::instance()->GetQuality();
            return $this->view('admin.add_label')->with('quality',$quality);
        }
    }

    /**
     * 修改标签
     * @return mixed
     * @author alice
     * @date 2016-2-19
     */
    public function EditLabel()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->label_id            =     $this->getParam('label_id');
            $aData->label_name          =     $this->getParam('label_name');
            $aData->quality             =     $this->getParam('quality');

            #逻辑操作
            GoodsService::instance()->EditLabel($aData);
            return Redirect::to('/show_label');}else{
            $id   = $this->getParam('label_id');
            $info = GoodsService::instance()->GetLabelInfo($id);
            #材质
            $quality = GoodsService::instance()->GetQuality();
            return $this->view('admin.edit_label')->with(['quality'=>$quality,'label'=>$info]);
        }
    }

    /**
     * 展示规格列表
     * @return mixed
     * @author alice
     * @date 2016-2-20
     */
    public function ShowSpecList()
    {
        $info = GoodsService::instance()->ShowSpecList();
        return $this->view('admin.show_spec')->with('specs',$info);
    }

    /**
     * 添加规格
     * @return mixed
     * @author alice
     * @date 2016-2-20
     */
    public function AddSpec()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->spec_name            =     $this->getParam('spec_name');
            $aData->quality              =     $this->getParam('quality');

            #逻辑操作
            GoodsService::instance()->AddSpec($aData);
            return Redirect::to('/show_spec');}else{
            $quality = GoodsService::instance()->GetQuality();
            return $this->view('admin.add_spec')->with('quality',$quality);
        }
    }

    /**
     * 修改规格
     * @return mixed
     * @author alice
     * @date 2016-2-20
     */
    public function EditSpec()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->spec_id            =     $this->getParam('spec_id');
            $aData->spec_name          =     $this->getParam('spec_name');
            $aData->quality            =     $this->getParam('quality');

            #逻辑操作
            GoodsService::instance()->EditSpec($aData);
            return Redirect::to('/show_spec');
        }else{
            $id   = $this->getParam('spec_id');
            $info = GoodsService::instance()->GetSpecInfo($id);
            #材质
            $quality = GoodsService::instance()->GetQuality();
            return $this->view('admin.edit_spec')->with(['spec'=>$info,'quality'=>$quality]);
        }
    }

    /**
     * 等级列表
     * @return mixed
     * @author alice
     * @date 2016-2-19
     */
    public function ShowLevelList()
    {

        $info = GoodsService::instance()->ShowLevelList();
        return $this->view('admin.show_level')->with('levels',$info);
    }

    /**
     * 添加等级
     * @return mixed
     * @author alice
     * @date 2016-2-19
     */
    public function AddLevel()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->level_name                 =  $this->getParam('level_name');
            $aData->quality                    =  $this->getParam('quality');

            #逻辑操作
            GoodsService::instance()->AddLevel($aData);
            return Redirect::to('/show_level');}else{
            $quality = GoodsService::instance()->GetQuality();
            return $this->view('admin.add_level')->with('quality',$quality);
        }
    }

    /**
     * 修改等级
     * @return mixed
     * @author alice
     * @date 2016-2-19
     */
    public function EditLevel()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->level_id            =     $this->getParam('level_id');
            $aData->level_name          =     $this->getParam('level_name');
            $aData->quality             =     $this->getParam('quality');

            #逻辑操作
            GoodsService::instance()->EditLevel($aData);
            return Redirect::to('/show_level');}else{
            $id   = $this->getParam('level_id');
            $info = GoodsService::instance()->GetLevelInfo($id);
            #材质
            $quality = GoodsService::instance()->GetQuality();
            return $this->view('admin.edit_level')->with(['quality'=>$quality,'level'=>$info]);
        }
    }




}